package algotithm.weekendrace.biweeklycontest51.test2;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * @author 25068
 * @Date 2021/5/1 22:34
 * @Title 5731. 座位预约管理系统
 */
public class SeatManager {


    public static void main(String[] args) {
        SeatManager manager = new SeatManager(5);
        System.out.println(manager.reserve());
        System.out.println(manager.reserve());
        manager.unreserve(2);
        System.out.println(manager.reserve());
        System.out.println(manager.reserve());
        System.out.println(manager.reserve());
        System.out.println(manager.reserve());
        manager.unreserve(5);
        System.out.println(manager.reserve());
    }

    PriorityQueue<Integer> q = new PriorityQueue<>(new Comparator<Integer>() {
    @Override
    public int compare(Integer o1, Integer o2) {
        return o1 - o2;
    }
    });
    public SeatManager(int n) {
        for (int i = 1; i <= n; i++) {
            q.add(i);
        }
    }

    public int reserve() {
        return q.poll();
    }

    public void unreserve(int seatNumber) {
        q.add(seatNumber);
    }

}
